<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Iterator"%>
<%@page import="com.xhd.vo.Fruits"%>
<%@page import="java.util.List"%>
<%@page import="com.xhd.Dao.SalerDaoImpl"%>
<%@page import="com.xhd.Dao.SalerDao"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>查看今日水果界面</title>
<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<meta http-equiv="content-type" content="text/html;charset=utf-8">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<link rel="stylesheet" href="./css/Inf.css"/>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.css">
<style type="text/css">
	* {
		font-size: 11pt;
	}
	div {
		border: solid 2px rgb(78,78,78);
		width: 75px;
		height: 75px;
		text-align: center;
	}
	li {
		margin: 10px;
	}
</style>
</head>

 
 <body style="background: rgb(254,238,189);">
 <form action="SalerServlet?method=serchFruit" method="post">
 	<input type="text"  name="serchfruit">	<input type="submit"  name="serch" value="查询">
 	</form>
 	 <form action="SalerServlet?method=serchPrice" method="post">
 	<input width=10px type="text"  name="price1">————<input width=10px type="text"  name="price2"><input type="submit"  name="serchprice" value="查询价格区间">
 	</form>
<% 
	String price1 = (String)request.getAttribute("price1");
	String price2 = (String)request.getAttribute("price2");
	System.out.println(price1);
	System.out.println(price2);
	float p1=0.0f;
	float p2=0.0f;
	List<Fruits> serchlist = new ArrayList<Fruits>();
	serchlist=(List<Fruits>)request.getAttribute("serchlist");
	if(serchlist==null){
	SalerDao sd = new SalerDaoImpl();
	List<Fruits> fruitlist=sd.haveFruitOrNot("待售");
	List<Fruits> fruitlist2=sd.haveFruitOrNot("被冻结");
	Iterator<Fruits> fIter=fruitlist.iterator();
	Iterator<Fruits> fIter2=fruitlist2.iterator();
	int i=0;
	if (!fIter.hasNext()&&!fIter2.hasNext()){
%>	
	<div id="inf-box">
			<h6>水果已售空！</h6>
<a href="Jijie.jsp">查看当季水果推荐</a>
		</div>
<%	
	}
	else {
	%>
	<table border="1" width="100%" cellspacing="0" background="black">
	<tr bgcolor="rgb(78,78,78)" bordercolor="rgb(78,78,78)" align="center" style="color: white;">
			<td>水果图片</td>
			<td>水果名</td>
			<td>价格</td>
			<td>商品描述</td>
			<td></td>
	</tr>
	<%

		Fruits fruit=null;
		while(fIter.hasNext()){
			fruit=fIter.next();
	%>
	<tr bordercolor="rgb(78,78,78)" align="center">
	<td>
	<%
	if(price1!=null&&price2!=null){
		 p1 = Float.parseFloat(price1);
		 p2 = Float.parseFloat(price2);
			float fp = Float.parseFloat(fruit.getFruit_price());
			if(fp>=p1&&fp<=p2){

		int left = 0;
		int right = fruit.getFruit_picture().indexOf("@");
		if(right==-1){
			  right=fruit.getFruit_picture().length();
		  }
		String imagepath = fruit.getFruit_picture().substring(left,right);
		i++;
		String formname = "form"+i;
		%>
		<img style="height:100px; weight:100px;" src="./upload/<%=imagepath %>"></td>

		<td><%=fruit.getFruit_name() %></td>
		<td><%=fruit.getFruit_price()%></td>
		<td><%=fruit.getFruit_describe()%></td>
		<td>
		<form name='<%=formname%>' action='FruitDetail.jsp' method='post'>     
		<input type='hidden' name='name' value='<%=fruit.getFruit_name()%>'/>  	  
		<input type='hidden' name='price' value='<%=fruit.getFruit_price()%>'/> 
		<input type='hidden' name='describe' value='<%=fruit.getFruit_describe()%>'/> 
		<input type='hidden' name='picture' value='<%=fruit.getFruit_picture()%>'/>
		<input type='hidden' name='stock' value='<%=fruit.getFruit_stock()%>'/>
		<a href='javascript:document.<%=formname%>.submit();'>商品详情</a>  
		</form>
		</td>
	</tr>

   
	<%	
			}}else{
				int left = 0;
				int right = fruit.getFruit_picture().indexOf("@");
				if(right==-1){
					  right=fruit.getFruit_picture().length();
				  }
				String imagepath = fruit.getFruit_picture().substring(left,right);
				String formname = "form"+i;
				%>
				<img style="height:100px; weight:100px;" src="./upload/<%=imagepath %>"></td>

				<td><%=fruit.getFruit_name() %></td>
				<td><%=fruit.getFruit_price()%></td>
				<td><%=fruit.getFruit_describe()%></td>
				<td>
				<form name='<%=formname%>' action='FruitDetail.jsp' method='post'>     
				<input type='hidden' name='name' value='<%=fruit.getFruit_name()%>'/>  	  
				<input type='hidden' name='price' value='<%=fruit.getFruit_price()%>'/> 
				<input type='hidden' name='describe' value='<%=fruit.getFruit_describe()%>'/> 
				<input type='hidden' name='picture' value='<%=fruit.getFruit_picture()%>'/> 
				<input type='hidden' name='stock' value='<%=fruit.getFruit_stock()%>'/>
				<a href='javascript:document.<%=formname%>.submit();'>商品详情</a>  
				</form>
				</td>
			</tr>
		
		<%
		i++;
			}
		}
		Fruits fruit2=null;
		while(fIter2.hasNext()){
			fruit2=fIter2.next();
	%>
		<tr bordercolor="rgb(78,78,78)" align="center">
		<td>
	<%
	if(price1!=null&&price2!=null){
		float fp = Float.parseFloat(fruit2.getFruit_price());
		 p1 = Float.parseFloat(price1);
		 p2 = Float.parseFloat(price2);
		if(fp>=p1&&fp<=p2){
	int left = 0;
	int right = fruit2.getFruit_picture().indexOf("@");
	if(right==-1){
		  right=fruit2.getFruit_picture().length();
	  }
		String imagepath = fruit2.getFruit_picture().substring(left,right);
		%>
		<img style="height:100px; weight:100px;" src="./upload/<%=imagepath %>"></td>
		
		<td><%=fruit2.getFruit_name() %></td>
		<td><%=fruit2.getFruit_price()%></td>
		<td><%=fruit2.getFruit_describe()%></td>
		<td>当前水果被冻结，无法购买</td>
	</tr>
	<%
		}}else{
			int left = 0;
			int right = fruit2.getFruit_picture().indexOf("@");
			if(right==-1){
				  right=fruit2.getFruit_picture().length();
			  }
				String imagepath = fruit2.getFruit_picture().substring(left,right);
				%>
				<img style="height:100px; weight:100px;" src="./upload/<%=imagepath %>"></td>
				
				<td><%=fruit2.getFruit_name() %></td>
				<td><%=fruit2.getFruit_price()%></td>
				<td><%=fruit2.getFruit_describe()%></td>
				<td>当前水果被冻结，无法购买</td>
			</tr>
			<%
		}
	}
	%>
	</table>	
	<p style="text-align: center;"><a href="HomePage.jsp">返回主界面</a></p><br/>
<% 
}
	}else{
		Iterator<Fruits> sfIter=serchlist.iterator();
		if (!sfIter.hasNext()){
		%>	
			抱歉，找不到商品！<br>		
			<a href="CheckFruits.jsp">点击此处</a>返回
		<%	
			}
			else {
				Fruits serchfruit=null;
				int count =0;
				int i=900;
				while(sfIter.hasNext()){
					serchfruit=sfIter.next();
					//System.out.println("serch:"+serchfruit.getFruit_describe());
					//System.out.println("serch:"+serchfruit.getFruit_state());
					if(price1!=null&&price2!=null){
						 p1 = Float.parseFloat(price1);
						 p2 = Float.parseFloat(price2);
					float fp = Float.parseFloat(serchfruit.getFruit_price());
						if(fp>=p1&&fp<=p2){
							if(serchfruit.getFruit_state().equals("待售")||serchfruit.getFruit_state().equals("被冻结")){
							count++;
					
		%>
		<table border="1" width="100%" cellspacing="0" background="black">
		<tr bgcolor="rgb(78,78,78)" bordercolor="rgb(78,78,78)" align="center" style="color: white;">
	
			<td>水果图片</td>
			<td>水果名</td>
			<td>价格</td>
			<td>商品描述</td>
			<td></td>
	
		</tr>
		<tr bordercolor="rgb(78,78,78)" align="center">
	    <td>
		<%
		
		int left = 0;
		int right = serchfruit.getFruit_picture().indexOf("@");
		if(right==-1){
			  right=serchfruit.getFruit_picture().length();
		  }
			String imagepath = serchfruit.getFruit_picture().substring(left,right);
			String formname = "form"+i;
			%>
		<img style="height:100px; weight:100px;" src="./upload/<%=imagepath %>"></td>
			
			<td><%=serchfruit.getFruit_name() %></td>
			<td><%=serchfruit.getFruit_price()%></td>
			<td><%=serchfruit.getFruit_describe()%></td>
			<td>
				<form name='<%=formname %>' action='FruitDetail.jsp' method='post'>     
				<input type='hidden' name='name' value='<%=serchfruit.getFruit_name()%>'/>  	  
				<input type='hidden' name='price' value='<%=serchfruit.getFruit_price()%>'/> 
				<input type='hidden' name='describe' value='<%=serchfruit.getFruit_describe()%>'/> 
				<input type='hidden' name='picture' value='<%=serchfruit.getFruit_picture()%>'/> 
				<input type='hidden' name='stock' value='<%=serchfruit.getFruit_stock()%>'/>
				<a href='javascript:document.<%=formname %>.submit();'>商品详情</a>  
				</form>
			</td>
		</tr>
	</table>
	<% 
		i++;			}//count
						}}else{
							if(serchfruit.getFruit_state().equals("待售")||serchfruit.getFruit_state().equals("被冻结")){
								count++;
						
			%>
			<table border="1" width="100%" cellspacing="0" background="black">
			<tr bgcolor="rgb(78,78,78)" bordercolor="rgb(78,78,78)" align="center" style="color: white;">
		
				<td>水果图片</td>
				<td>水果名</td>
				<td>价格</td>
				<td>商品描述</td>
				<td></td>
		
			</tr>
			<tr bordercolor="rgb(78,78,78)" align="center">
		    <td>
			<%
			
			int left = 0;
			int right = serchfruit.getFruit_picture().indexOf("@");
			if(right==-1){
				  right=serchfruit.getFruit_picture().length();
			  }
				String imagepath = serchfruit.getFruit_picture().substring(left,right);
				String formname = "form"+i;
				%>
			<img style="height:100px; weight:100px;" src="./upload/<%=imagepath %>"></td>
				
				<td><%=serchfruit.getFruit_name() %></td>
				<td><%=serchfruit.getFruit_price()%></td>
				<td><%=serchfruit.getFruit_describe()%></td>
				<td>
					<form name='<%=formname %>' action='FruitDetail.jsp' method='post'>     
					<input type='hidden' name='name' value='<%=serchfruit.getFruit_name()%>'/>  	  
					<input type='hidden' name='price' value='<%=serchfruit.getFruit_price()%>'/> 
					<input type='hidden' name='describe' value='<%=serchfruit.getFruit_describe()%>'/> 
					<input type='hidden' name='picture' value='<%=serchfruit.getFruit_picture()%>'/> 
					<input type='hidden' name='stock' value='<%=serchfruit.getFruit_stock()%>'/>
					<a href='javascript:document.<%=formname %>.submit();'>商品详情</a>  
					</form>
				</td>
			</tr>
		</table>
		<% 
						}
						}//else
						
				}//while
			if(count==0){
			%>
			抱歉，找不到商品！<br>		
			<a href="CheckFruits.jsp">点击此处</a>返回
		<% }
			}
			}
%>
</body>
</html>